﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Windows.Forms;

namespace FormatingExercise
{
    class FormattingExercises
    {
        public static void PrintBytesHexademical(string line)
        {
            Encoding utf8 = Encoding.UTF8;
            byte[] bytes = utf8.GetBytes(line);

            foreach (byte character in bytes)
            {
                Console.Write(@"\0x{0:X}", character);
            }

            Console.WriteLine();
            Console.WriteLine(BitConverter.ToString(bytes));

            Console.WriteLine();
        }

        public static void PrintNumberTable(uint start, uint end)
        {
            Console.Write("|{0,5}|", "Number");
            Console.Write("|{0,6}|", "Square");
            Console.Write("|{0,10}|", "Sqrt");
            Console.WriteLine("|{0}", "lg");
            Console.WriteLine(new string('=', 50));

            for (uint i = start; i <= end; i++)
            {
                Console.Write("|{0,6}|", i);
                Console.Write("|{0,-6}|", i*i);
                Console.Write("|{0,-10:#.####}|", Math.Sqrt(i));
                Console.WriteLine("|{0}", Math.Log(i));
                Console.WriteLine(new string('_', 50));
            }
        }

        public static void ReadRealNumber()
        {
            string buffer = "";
            buffer = Console.ReadLine();
            double number = 0;

            try
            {
                number = double.Parse(buffer);
            }
            catch
            {
                throw new ArgumentException("Incorrect format.");
            }

            PrintRealNumberInFormat(number);
        }

        public static void PrintRealNumberInFormat(double number)
        {
            CultureInfo cultureAustria = new CultureInfo("de-AT");
            PrintAmount(number, cultureAustria);

            CultureInfo cultureBg = new CultureInfo("bg-BG");
            PrintAmount(number, cultureBg);

            CultureInfo cultureIsrael = new CultureInfo("he-IL");
            PrintAmount(number, cultureIsrael);

            CultureInfo cultureMongol = new CultureInfo("mn-MN");
            PrintAmount(number, cultureMongol);
        }

        private static void PrintAmount(double amount, CultureInfo culture)
        {
            string message = String.Format(culture, "Amount {0:C} ", amount);
            string caption = culture.EnglishName;

            MessageBox.Show(message, caption);
            //Console.WriteLine(message, caption);
        }

        static void Main(string[] args)
        {
            //PrintBytesHexademical("Hi!");
            //PrintNumberTable(1,25);
            //Fraction frac = new Fraction(1, 6);
            //Console.WriteLine(frac);
            //Console.WriteLine("{0:N}", frac);
            //Console.WriteLine("{0:R}", frac);
            ReadRealNumber();
        }
    }
}
